import { find } from 'lodash';

export const getTableColumns = ({ params, orgList }: any) => [
	{
		title: "设备编号",
		dataIndex: "id",
		width: 140,
		ellipsis: true
	},
	{
		title: "设备名称",
		dataIndex: "name",
		width: 140,
		ellipsis: true
	},
	{
		title: "供应商",
		dataIndex: "supplier",
		width: 140,
		ellipsis: true
	},
	{
		title: "联系人",
		dataIndex: "callName",
		width: 140,
		ellipsis: true
	},
	{
		title: "联系电话",
		dataIndex: "callPhone",
		width: 100,
		ellipsis: true,
	},
	{
		title: "所属组织",
		dataIndex: "createOrgId",
		width: 100,
		ellipsis: true,
		render: (_: any, record: any) => {
			const result = find(orgList?.data || [], (item: any) => item.id === record.createOrgId)
			return (
				<span>
					{result?.name}
				</span>
			)
		}
	},
	{
		title: "创建时间",
		dataIndex: "createTime",
		width: 100,
		ellipsis: true,
	},
	{
		title: "过期时间",
		dataIndex: "expirationTime",
		width: 140,
		ellipsis: true
	},
];

export const USER_STATUS = [
	{ label: '在线', value: 1 },
	{ label: '离线', value: 2 }
]

export const getSearchColumns = ({orgList}: any) => [
	{
		type: "input",
		placeholder: "V2X设备名称",
		name: "name"
	},
	{
		type: "select",
		placeholder: "所属组织",
		name: "createOrgId",
		options: orgList?.data || [],
		fieldProps:{
			fieldNames: {
				label: 'name',  // 显示文本对应的字段
				value: 'id',    // 值对应的字段
			}
		}
	},
	{
		type: "input",
		placeholder: "供应商",
		name: "supplier"
	},
]



export const getCreateColumns = () => {
	return [
		{
			type: "input",
			placeholder: "设备名称",
			label: "设备名称",
			name: "name",
			rules: [{ required: true, message: '这是必填项' }]
		},
		{
			type: "input",
			placeholder: "供应商",
			label: "供应商",
			name: "supplier",
			rules: [
				{ required: true, message: '这是必填项' },
			]
		},
		{
			type: "input",
			placeholder: "联系人",
			label: "联系人",
			name: "callName",
			rules: [
				{ required: true, message: '这是必填项' },
			]
		},
		{
			type: "input",
			placeholder: "联系电话",
			label: "联系电话",
			name: "callPhone",
			rules: [{ required: true, message: '这是必填项' }]
		},
	]
}
